var Rushee = function(req, res, next) {
	if (typeof (req.user) == 'undefined') {
		res.redirect('/');
		return;
	}

	if (/Rushee|Member|Administrator/i.test(req.user.type)) {
		next();
	} else {
		res.redirect('/');
	}
};

var Member = function(req, res, next) {
	if (typeof (req.user) == 'undefined') {
		res.redirect('/');
		return;
	}

	if (/Member|Administrator/i.test(req.user.type)) {
		next();
	} else {
		res.redirect('/');
	}
};

var Administrator = function(req, res, next) {
	if (typeof (req.user) == 'undefined') {
		res.redirect('/');
		return;
	}

	if (/Administrator/i.test(req.user.type)) {
		next();
	} else {
		res.redirect('/');
	}
};

var User = function(req, res, next) {
	if (typeof (req.user) == 'undefined') {
		res.redirect('/');
		return;
	}

	if (/Administrator/i.test(req.user.type)
			|| req.params.id == req.user._id
			|| req.body.id == req.user._id) {
		next();
	} else {
		res.redirect('/');
	}
};

module.exports.rushee = Rushee;
module.exports.member = Member;
module.exports.admin = Administrator;
module.exports.user = User;
